package com.dog.basics.api.controller.mtkj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.api.mtkj.ApiGoodAddDto;
import com.dog.basics.bean.dto.api.mtkj.ApiGoodEditDto;
import com.dog.basics.bean.dto.api.mtkj.ApiGoodFromDto;
import com.dog.basics.bean.vo.api.mtkj.ApiGoodsVo;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.security.annotation.Inner;
import com.dog.basics.service.mtkj.IMtGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@Api(value = "商品模块",tags = SwaggerConstants.API_ALL)
@RestController
@RequestMapping("/api/goods")
@AllArgsConstructor
public class MtGoodsController {

    private final IMtGoodsService goodsService;

    /**
     * 根据商铺id获取商品列表分页信息
     *      1.搜索商品 并根据 创建时间，销量，价格 进行排序
     *      2.获取店铺商品 并根据 创建时间，销量，价格 进行排序
     *      3.根据商品类别获取商品分页信息 并根据 创建时间，销量，价格 进行排序
     *      4.根据商铺商品类别获取获取分页信息 并根据 创建时间，销量，价格 进行排序
     * @param page
     * @param goodFromDto
     * @return
     */
    @ApiOperation(value = "根据商铺id获取商品列表分页信息", notes = "根据商铺id获取商品列表分页信息", tags = SwaggerConstants.API_GOODS)
    @GetMapping("/page")
    @Inner
    public R<IPage<ApiGoodsVo>> page(PageParam page, ApiGoodFromDto goodFromDto){
        IPage<ApiGoodsVo> list = goodsService.getPageList(page, goodFromDto);
        return R.ok(list);
    }


    /**
     * 获取商品详情
     * @param: * @param: goodId
     * @return: com.dog.basics.common.util.R<com.dog.basics.bean.vo.api.mtkj.GoodsVo>
     * @author hangdy
     * @date: 2020/11/12 9:27
     */
    @ApiOperation(value = "获取商品详情", notes = "获取商品详情",tags = SwaggerConstants.API_GOODS)
    @ApiImplicitParam(value = "商品Id", name = "goodId", dataType = "Long", required = true)
    @GetMapping("/findOne/{goodId}")
    @Inner
    public R<ApiGoodsVo> findById(@PathVariable Long goodId){
        return R.ok(goodsService.getGoodById(goodId));
    }

    /**
     *  商品上下架
     * @param: goodId 商品id
     * @return: com.dog.basics.common.util.R<java.lang.Boolean>
     * @author hangdy
     * @date: 2020/11/12 9:57
     */
    @ApiOperation(value = "商品上下架", notes = "商品上下架", tags = SwaggerConstants.API_GOODS)
    @ApiImplicitParam(value = "商品Id", name = "goodId", dataType = "Long", required = true)
    @PutMapping("/upOrDown/{goodId}")
    public R<Boolean> GoodUpOrDown(@PathVariable Long goodId){
        return R.ok(goodsService.goodUpOrDown(goodId));
    }


    /**
     * 增加商品
     * @param obj
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "增加商品", notes = "增加商品",tags = SwaggerConstants.API_GOODS)
    @PostMapping("/save")
    public R<Boolean> save(@Valid @RequestBody ApiGoodAddDto obj) {
        return R.ok(goodsService.saveGood(obj));
    }

    /**
     * 修改商品
     * @param obj
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "修改商品", notes = "修改商品", tags = SwaggerConstants.API_GOODS)
    @PutMapping("/edit")
    public R<Boolean> edit(@Valid @RequestBody ApiGoodEditDto obj) {
        return R.ok(goodsService.editGood(obj));
    }


    /**
     * 删除商品
     * @param id
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "删除商品", notes = "删除商品", tags = SwaggerConstants.API_GOODS)
    @ApiImplicitParam(value = "商品Id", name = "goodId", dataType = "Long", required = true)
    @DeleteMapping("/delete/{goodId}")
    public R<Boolean> delete(@Valid @PathVariable("goodId") Long id) {
        return R.ok(goodsService.deleteGood(id));
    }



}
